home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / insert.doc < prev    next >
Text File  |  1995-03-31  |  2KB  |  54 lines

  1. INSERT by Joe Horn 
  2.  
  3. PURPOSE: Inserts an object into a list at any desired position. 
  4.  
  5. SYNTAX: {list} <position> <object>  -->  { new list } 
  6.  
  7.         Note: The syntax is identical to the PUT command's syntax, and 
  8.         the result is similar to PUT, with one difference: instead of 
  9.         *replacing* the old object at <position>, the new <object> is 
  10.         *inserted* there, pushing the old object (and everything after 
  11.         it) further down the list.  Therefore INSERT makes a list's 
  12.         SIZE grow by 1, whereas PUT leaves it the same. 
  13.  
  14. Note:   Although this program allows you to "insert" an object at the 
  15.         beginning or end of a list, it is faster to use + or SWAP +. 
  16.  
  17. EXAMPLE: Insert 'X' into { 9 8 7 6 5 } at the 2nd position. 
  18.  
  19.          { 9 8 7 6 5 }  2  'X' 
  20.          INSERT  -->  { 9 X 8 7 6 5 } 
  21.  
  22.          How does this differ from PUT? 
  23.  
  24.          { 9 8 7 6 5 }  2  'X' 
  25.          PUT  -->  { 9 X 7 6 5 }   notice that the 8 got replaced. 
  26.  
  27. THEORY: There is a System RPL word designed to do this job, but it 
  28.         uses local variables, which makes it rather slow.  The INSERT 
  29.         program here is written in User RPL but is faster than the 
  30.         System RPL word, because it uses only fast stack operations. 
  31.         Herein lies a moral.  Software development time can be saved 
  32.         by the use of local variables, but program execution time is 
  33.         sacrificed.  Use only stack operations if you have the time 
  34.         and patience to do the step-by-step stack analysis required. 
  35.  
  36. STACK ANALYSIS: 
  37.  
  38. <<        { L1 L2 ... Ln }  pos  obj 
  39. ROT       pos  obj  { L1 L2 ... Ln } 
  40. OBJ\->    pos  obj  L1 L2 ... Ln  n 
  41. 1 +       pos  obj  L1 L2 ... Ln  n+1 
  42. DUP       pos  obj  L1 L2 ... Ln  n+1  n+1 
  43. 1 +       pos  obj  L1 L2 ... Ln  n+1  n+2 
  44. ROLL      pos  L1 L2 ... Ln  n+1  obj 
  45. OVER      pos  L1 L2 ... Ln  n+1  obj  n+1 
  46. DUP       pos  L1 L2 ... Ln  n+1  obj  n+1  n+1 
  47. 3 +       pos  L1 L2 ... Ln  n+1  obj  n+1  n+4 
  48. ROLL      L1 L2 ... Ln  n+1  obj  n+1  pos 
  49. -         L1 L2 ... Ln  n+1  obj  n+1-pos 
  50. 2 +       L1 L2 ... Ln  n+1  obj  n+3-pos 
  51. ROLLD     L1 L2 ... Ln  n+1 
  52. \->LIST   { L1 L2 ... Ln } 
  53. \>> 
  54.